/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ania2.gui;

import ania2.Move;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author pawel
 */
public class GameRecordTableModel extends AbstractTableModel {

    private List<Move> dataList;

    public GameRecordTableModel(List<Move> dataList) {
        this.dataList = dataList;
    }

    public int getColumnCount() {
        return 3;
    }

    public int getRowCount() {
        return Math.round(dataList.size() / 2);
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        try {
            if (columnIndex == 0) {
                return rowIndex + 1;
            } else if (columnIndex == 1) {
                return dataList.get(rowIndex * 2 + 1);
            } else {
                return dataList.get(rowIndex * 2 + 2);
            }
        } catch (IndexOutOfBoundsException e) {
            //e.printStackTrace();
            return null;
        }
    }

    @Override
    public String getColumnName(int c) {
        if (c == 0) {
            return "Nr";
        } else if (c == 1) {
            return "Białe";
        } else {
            return "Czarne";
        }
    }
}
